//服务层
app.service('goodsService',function($http){
	    	
	//读取列表数据绑定到表单中
	this.findAll=function(){
		return $http.get('../goods/findAll.do');		
	}
	//分页 
	this.findPage=function(page,rows){
		return $http.get('../goods/findPage.do?page='+page+'&rows='+rows);
	}
	//查询实体
	this.findOne=function(id){
		return $http.get('../goods/findOne.do?id='+id);
	}
	//增加 
	this.add=function(entity){
		return  $http.post('../goods/add.do',entity );
	}
	//修改 
	this.update=function(entity){
		return  $http.post('../goods/update.do',entity );
	}
	//删除
	this.dele=function(ids){
		return $http.get('../goods/delete.do?ids='+ids);
	}
	//搜索
	this.search=function(page,rows,searchEntity){
		return $http.post('../goods/search.do?page='+page+"&rows="+rows, searchEntity);
	}

	//将前端的文件上传到后台（前端：利用h5+angularjs技术，后端：springmvc+commonsMultipartResolver组件）
	this.upload = function () {
		//1.定义要上传的数据对象
		var data = new FormData();
		data.append("file",file.files[0]);
		//2.进行文件上传
		return $http({
			url:'../upload.do',
			data:data,
			method:'post',
			headers:{'Content-Type' :undefined},  //如果这里是undefined,前端就会将其转换为：multipart/form-data
			transformRequest:angular.identity     //angular对上传的数据进行序列化处理
		})
	}
});
